package cc.rengu.igas.momp.core.service.trans;

import cc.rengu.igas.momp.common.constant.CommonConstant;
import cc.rengu.igas.momp.common.dao.*;
import cc.rengu.igas.momp.common.dao.impl.*;
import cc.rengu.igas.momp.common.entity.*;
import cc.rengu.igas.momp.common.enums.*;
import cc.rengu.igas.momp.common.model.bean.*;
import cc.rengu.igas.momp.common.util.JsonOperation;
import cc.rengu.igas.momp.facade.bean.McListInfoBean;
import cc.rengu.igas.momp.facade.request.QueryMcListInfoRequest;
import cc.rengu.igas.momp.facade.response.QueryMcListInfoResponse;
import cc.rengu.oltp.service.base.RadpService;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.enums.ChannelEnum;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.utility.util.ConvertUtil;
import cc.rengu.oltp.utility.util.DateUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.base.StringUtil;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 营销活动列表信息查询
 *
 * @author Jinan Liu
 * @date 2020/3/28 10:39
 */
public class QueryMcListInfoService extends RadpService {

    private String mcName;
    private String queryOrgId;
    private String queryRole;
    private String queryType;
    private List<TMMcOrgInfo> tmMcOrgInfoList = new ArrayList<>();
    private String globalInstId;
    private String globalTransDate;
    private String globalTraceNo;
    /*营销活动类型*/
    private String globalMcType;
    /*营销活动查询开始时间*/
    private String globalStartTime;
    /*营销活动查询结束时间*/
    private String globalEndTime;

    @Override
    protected int bizInit(String s) {
        return CommonConstant.PROCESS_SUCCESS;
    }

    @Override
    protected int bizProcess(String s, int i) {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        try {

            QueryMcListInfoRequest queryMcListInfoRequest = new QueryMcListInfoRequest();
            ConvertUtil.convertOutput(queryMcListInfoRequest);

            QueryMcListInfoResponse queryMcListInfoResponse = new QueryMcListInfoResponse();
            queryMcListInfoResponse.setHeader(queryMcListInfoRequest.getHeader());
            BizResponse<QueryMcListInfoResponse> bizResponse = new BizResponse<>();
            bizResponse.setResult(queryMcListInfoResponse);
            queryOrgId = queryMcListInfoRequest.getQueryOrgId();
            queryRole = queryMcListInfoRequest.getQueryRole();
            queryType = queryMcListInfoRequest.getQueryType();
            globalStartTime = queryMcListInfoRequest.getStartTime();
            globalEndTime = queryMcListInfoRequest.getEndTime();

            /* 请求报文检查，同时全局变量赋值 */
            messageValidation(queryMcListInfoRequest);
            //查询上送机构及下属机构
            McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
            tmMcOrgInfoList = mcOrgInfoMapper.selectAllMcOrgInfoListByinstIdOrgId(queryMcListInfoRequest.getHeader().getInstId(), queryOrgId);
            if (null == tmMcOrgInfoList || tmMcOrgInfoList.size() == 0) {
                /* 代理商、收银员或用户 */
                rglog.error("查询当前角色<{}>机构<{}>及其下属机构失败!", queryMcListInfoRequest.getQueryRole(), queryOrgId);
                throw new BizException(RespCodeEnum.GET_MC_ORG_INFO_ERROR.getRespCode(), RespCodeEnum.GET_MC_ORG_INFO_ERROR.getRespDesc());
            }
            BizResponse<QueryMcListInfoResponse> bizResponseTmp = queryMcListInfo(queryMcListInfoRequest, queryMcListInfoResponse);
            ConvertUtil.convertInput(bizResponseTmp.getResult());

        } catch (BizException e) {
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, e.getCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, e.getMessage());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e1));
            }
        } catch (Exception e) {
            rglog.error(StringUtil.ExceptionToString(e));
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e));
            }
        }

        return CommonConstant.PROCESS_SUCCESS;
    }

    @Override
    protected int bizTerminate(String s) {
        return CommonConstant.PROCESS_SUCCESS;
    }

    /**
     * 营销活动列表信息查询
     *
     * @param queryMcListInfoRequest  营销活动列表查询接口请求对象
     * @param queryMcListInfoResponse 营销活动列表查询接口应答对象
     * @return cc.rengu.oltp.service.model.BizResponse<cc.rengu.igas.momp.facade.response.QueryMcListInfoResponse> 营销活动列表查询接口应答对象
     * @throws BizException 异常信息
     * @author Jinan Liu
     * @date 2020/5/18 11:57
     */
    private BizResponse<QueryMcListInfoResponse> queryMcListInfo(QueryMcListInfoRequest queryMcListInfoRequest, QueryMcListInfoResponse queryMcListInfoResponse) throws Exception {

        BizResponse<QueryMcListInfoResponse> bizResponse = new BizResponse<>();

        List<McListInfoBean> mcListInfoBeanList = new ArrayList<>();

        /* 判断查询类型 */
        String queryType = queryMcListInfoRequest.getQueryType();
        String queryId = queryMcListInfoRequest.getQueryId();
        String queryRole = queryMcListInfoRequest.getQueryRole();
        String mcType = queryMcListInfoRequest.getMcType();
        mcName = queryMcListInfoRequest.getMcName();
        /* 先查询所有数据，在判断查询用户是否有权限获取到数据 */
        if (QueryTypeEnum.BANK_QUERY_TYPE.getQueryTypeCode().equals(queryType)) {

            /* 银行人员 */
            if (!QueryRoleEnum.BANK_AUDIT_QYERY_ROLE.getQueryRoleCode().equals(queryRole)) {

                /* 录入岗和发布岗 */

                /* 银行录入岗或银行发布岗 */
                if (QueryRoleEnum.BANK_BASIC_QUERY_ROLE.getQueryRoleCode().equals(queryRole)) {
                    /* 录入岗查询数据 */
                    selectToClientMcListInfoByBankBasicRole(queryMcListInfoRequest, mcListInfoBeanList);

                } else {
                    /* 发布岗查询数据 */
                    selectToClientMcListInfoByBankPublishRole(queryMcListInfoRequest, mcListInfoBeanList);

                }

            } else {
                /* 银行审批岗，查询业务数据临时表数据, 目前支持同时查询所有类型的营销活动的数据 */
                if (null != mcType) {
                    selectAllTmpMcListInfoByBankAuditRole(queryMcListInfoRequest, mcListInfoBeanList, mcType);
                } else {
                    selectAllTmpMcListInfoByBankAuditRole(queryMcListInfoRequest, mcListInfoBeanList, McTypeEnum.ALL_MC_TYPE.getMcTypeCode());
                }
            }

        } else if (QueryTypeEnum.MCHNT_QYERY_TYPE.getQueryTypeCode().equals(queryType)) {
            /* 商户,目前仅支持查询对客类营销活动，即同时查询减免类营销活动和卡券类营销活动的数据 */
            queryToClientMcListInfoByMchnt(queryMcListInfoRequest, mcListInfoBeanList);

        } else {
            /* 代理商、收银员或用户 */
            rglog.error("当前<{}>角色的查询类型的<{}>查询用户<{}>无权限查看数据!", queryRole, queryType, queryId);
            throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespDesc());
        }

        if (mcListInfoBeanList.isEmpty()) {
            rglog.info("根据查询条件查询到0条营销活动列表信息!");
            queryMcListInfoResponse.setTotalPage(CommonConstant.ZERO_COMMON_CONSTANT);
            queryMcListInfoResponse.setTotalRows(CommonConstant.ZERO_COMMON_CONSTANT);
        } else {
            //判断机构号
            if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getOrgId())) {
                McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
                try {
                    List<TMMcOrgInfo> tmMcOrgInfoList = mcOrgInfoMapper.selectMcOrgInfoListByinstIdOrgId(queryMcListInfoRequest.getHeader().getInstId(), queryMcListInfoRequest.getOrgId());
                    List<McListInfoBean> mcListInfoByorgIdList = new ArrayList<>();
                    for (TMMcOrgInfo tmMcOrgInfo : tmMcOrgInfoList) {
                        List<McListInfoBean> mcListInfoByorgIdList1 = mcListInfoBeanList.stream().filter(item -> item.getMcNo().equals(tmMcOrgInfo.getMcNo())).collect(Collectors.toList());
                        mcListInfoByorgIdList.addAll(mcListInfoByorgIdList1);
                    }
                    mcListInfoBeanList = mcListInfoByorgIdList;
                } catch (Exception e) {
                    rglog.error(e.getMessage());
                }
            }

            for (McListInfoBean mcListInfoBean : mcListInfoBeanList) {
                String thisMcType = mcListInfoBean.getMcType();
                if (McTypeEnum.REDUCTION_FIXED_AMOUNT.getMcTypeCode().equals(thisMcType) ||
                        McTypeEnum.REDUCTION_RANDOM_AMOUNT.getMcTypeCode().equals(thisMcType) ||
                        McTypeEnum.REDUCTION_FIXED_RATE.getMcTypeCode().equals(thisMcType) ||
                        McTypeEnum.REDUCTION_RANDOM_RATE.getMcTypeCode().equals(thisMcType) ||
                        McTypeEnum.COUPON_ALL.getMcTypeCode().equals(thisMcType) ||
                        McTypeEnum.COUPON_FREE.getMcTypeCode().equals(thisMcType) ||
                        McTypeEnum.COUPON_PAID.getMcTypeCode().equals(thisMcType)) {
                    //循环计算已经消耗的额度并赋值给返回的对象_对客的
                    String alredyUsed = calToClientAlredyUsedFee(mcListInfoBean.getMcNo(), mcListInfoBean.getMcStartDate(), mcListInfoBean.getMcType(), mcListInfoBean.getMcEndDate(), mcListInfoBean.getMcStatus());
                    mcListInfoBean.setBudgetUsed(alredyUsed);
                } else if (McTypeEnum.MCHNT_FEE_DISCOUNT.getMcTypeCode().equals(thisMcType)) {
                    //循环计算已经消耗的额度并赋值给返回的对象_手续费的
                    String alredyUsed = calMchntFeeDiscountAlredyUsedFee(mcListInfoBean.getMcNo(), mcListInfoBean.getMcStartDate(), mcListInfoBean.getMcType(), mcListInfoBean.getMcEndDate(), mcListInfoBean.getMcStatus());
                    mcListInfoBean.setBudgetUsed(alredyUsed);
                }
            }

            queryMcListInfoResponse.setTotalRows(String.valueOf(mcListInfoBeanList.size()));
            if (queryMcListInfoRequest.getPageIndex().equals("-1") || queryMcListInfoRequest.getPageSize().equals("-1")) {
                queryMcListInfoResponse.setTotalPage(CommonConstant.ONE_COMMON_CONSTANT);
                queryMcListInfoResponse.setPageIndex(CommonConstant.ONE_COMMON_CONSTANT);
                queryMcListInfoResponse.setPageSize(String.valueOf(mcListInfoBeanList.size()));
                //查询到的链表信息
                queryMcListInfoResponse.setMcInfoList(mcListInfoBeanList);
            } else {
                if (CommonConstant.ZERO == (mcListInfoBeanList.size() % Integer.parseInt(queryMcListInfoRequest.getPageSize()))) {
                    queryMcListInfoResponse.setTotalPage(String.valueOf(mcListInfoBeanList.size() / Math.abs(Integer.parseInt(queryMcListInfoRequest.getPageSize()))));
                } else {
                    queryMcListInfoResponse.setTotalPage(String.valueOf(mcListInfoBeanList.size() / Math.abs(Integer.parseInt(queryMcListInfoRequest.getPageSize())) + 1));
                }
                /* 获取所有订单信息 */
                if (CommonConstant.NO_LIMIT_COMMON_CONSTANT.equals(queryMcListInfoRequest.getPageIndex()) || CommonConstant.NO_LIMIT_COMMON_CONSTANT.equals(queryMcListInfoRequest.getPageSize())) {
                    /* 拼接交易信息 */
                    mcListInfoBeanList.sort(Comparator.comparingInt(x -> Integer.parseInt(x.getCreateTime())));
                    queryMcListInfoResponse.setMcInfoList(mcListInfoBeanList);
                } else {
                    //银行录入岗排序
                    if (QueryRoleEnum.BANK_BASIC_QUERY_ROLE.getQueryRoleCode().equals(queryRole)) {
                        Comparator<McListInfoBean> mcStatusSort = Comparator.comparing(McListInfoBean::getMcStatusSort);
                        Comparator<McListInfoBean> mcEndDate = Comparator.comparing(McListInfoBean::getMcEndDate);
                        Comparator<McListInfoBean> budget = Comparator.comparingDouble((McListInfoBean mcListInfoBean) -> Double.parseDouble(mcListInfoBean.getBudget())).reversed();
                        mcListInfoBeanList.sort(mcStatusSort.thenComparing(mcEndDate).thenComparing(budget));
                    } else if (QueryRoleEnum.BANK_PUBLISH_QYERY_ROLE.getQueryRoleCode().equals(queryRole)) {//银行发布岗
                        Comparator<McListInfoBean> updataTime = Comparator.comparing(item -> item.getUpdateTime().replaceAll("-", "").replaceAll(":", "").replaceAll(" ", "").replaceAll("\\.", ""));
                        Comparator<McListInfoBean> budget = Comparator.comparingDouble((McListInfoBean mcListInfoBean) -> Double.parseDouble(mcListInfoBean.getBudget())).reversed();
                        mcListInfoBeanList.sort(updataTime.thenComparing(budget));
                    } else {//银行审核员
                        Comparator<McListInfoBean> updataTime = Comparator.comparing(item -> item.getUpdateTime().replaceAll("-", "").replaceAll(":", "").replaceAll(" ", "").replaceAll("\\.", ""));
                        Comparator<McListInfoBean> mcEndDate = Comparator.comparing(McListInfoBean::getMcEndDate);
                        Comparator<McListInfoBean> budget = Comparator.comparingDouble((McListInfoBean mcListInfoBean) -> Double.parseDouble(mcListInfoBean.getBudget())).reversed();
                        mcListInfoBeanList.sort(updataTime.thenComparing(mcEndDate).thenComparing(budget));
                    }
                    /* 分页查询 */
                    int fromIndex = Integer.parseInt(queryMcListInfoRequest.getPageIndex()) * Integer.parseInt(queryMcListInfoRequest.getPageSize());
                    int endIndex = fromIndex + Integer.parseInt(queryMcListInfoRequest.getPageSize());
                    if (fromIndex <= mcListInfoBeanList.size()) {
                        List<McListInfoBean> mcListInfoBeanList1 = mcListInfoBeanList.subList(fromIndex, Math.min(endIndex, mcListInfoBeanList.size()));
                        queryMcListInfoResponse.setMcInfoList(mcListInfoBeanList1);
                    }
                }
            }
        }

        bizResponse.setRspSysId(ChannelEnum.MOMP.getChannelType());
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());

        queryMcListInfoResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        queryMcListInfoResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        queryMcListInfoResponse.setPageIndex(queryMcListInfoRequest.getPageIndex());
        queryMcListInfoResponse.setPageSize(queryMcListInfoRequest.getPageSize());
        bizResponse.setResult(queryMcListInfoResponse);

        return bizResponse;
    }

    /**
     * 银行操作员查询营销活动列表数据
     *
     * @param queryMcListInfoRequest 营销活动列表查询接口请求对象
     * @param mcListInfoBeanList     营销活动列表信息
     * @author Jinan Liu
     * @date 2020/5/18 11:58
     */
    private void selectToClientMcListInfoByBankBasicRole(QueryMcListInfoRequest queryMcListInfoRequest, List<McListInfoBean> mcListInfoBeanList) {

        try {

            MoMcListInfoInObj moMcListInfoInObj = (MoMcListInfoInObj) setupDatabaseInputObject(queryMcListInfoRequest, McTypeEnum.MC_TYPE_MO.getMcTypeCode());
            CpMcListInfoInObj cpMcListInfoInObj = (CpMcListInfoInObj) setupDatabaseInputObject(queryMcListInfoRequest, McTypeEnum.MC_TYPE_CP.getMcTypeCode());

            /* 机构编号 */
            if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getQueryOrgId())) {
                moMcListInfoInObj.setOrgId(queryMcListInfoRequest.getQueryOrgId());
                cpMcListInfoInObj.setOrgId(queryMcListInfoRequest.getQueryOrgId());
            }
            if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getOrgId())) {
                moMcListInfoInObj.setOrgId(queryMcListInfoRequest.getOrgId());
                cpMcListInfoInObj.setOrgId(queryMcListInfoRequest.getOrgId());
            }
            if (!StringUtil.isNullorEmpty(globalStartTime)) {
                moMcListInfoInObj.setStartTime(globalStartTime);
                cpMcListInfoInObj.setStartTime(globalStartTime);
            }
            if (!StringUtil.isNullorEmpty(globalEndTime)) {
                moMcListInfoInObj.setEndTime(globalEndTime);
                cpMcListInfoInObj.setEndTime(globalEndTime);
            }

            if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getCreateBy())) {
                moMcListInfoInObj.setOprId(queryMcListInfoRequest.getCreateBy());
                cpMcListInfoInObj.setOprId(queryMcListInfoRequest.getCreateBy());
            }

            /* 查询减免类营销活动数据 */
            McInfoListMapper mcInfoListMapper = new McInfoListMapperImpl();
            List<MoMcListInfoOutObj> moMcListInfoOutObjList = mcInfoListMapper.selectMoneyOffMcListInfoByBankBasicRole(moMcListInfoInObj);

            if (null != moMcListInfoOutObjList) {
                List<McListInfoBean> mcListInfoBeanList1 = moMcListInfoOutObjList.stream().map(this::convertMoneyOffMcListInfo).collect(Collectors.toList());
                if (null != queryMcListInfoRequest.getMcType() && !queryMcListInfoRequest.getMcType().equals(McTypeEnum.TO_CLIENT.getMcTypeCode())) {
                    mcListInfoBeanList1 = mcListInfoBeanList1.stream().filter(item -> item.getMcType().equals(queryMcListInfoRequest.getMcType())).collect(Collectors.toList());
                }
                if (null != queryMcListInfoRequest.getMcStatus() && queryMcListInfoRequest.getMcStatus().equals(McStatusEnum.ALL_ENDED.getMcStatusCode())) {
                    mcListInfoBeanList1 = mcListInfoBeanList1.stream().filter(item -> item.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode()) || item.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode())).collect(Collectors.toList());
                }
                mcListInfoBeanList.addAll(mcListInfoBeanList1);
            }

            /* 查询卡券类营销活动数据 */
            List<CpMcListInfoOutObj> cpMcListInfoOutObjList = mcInfoListMapper.selectCouponMcListInfoByBankBasicRole(cpMcListInfoInObj);
            if (null != cpMcListInfoOutObjList) {
                List<McListInfoBean> mcListInfoBeanList1 = cpMcListInfoOutObjList.stream().map(this::convertCouponMcListInfo).collect(Collectors.toList());
                if (null != queryMcListInfoRequest.getMcType() && !queryMcListInfoRequest.getMcType().equals(McTypeEnum.TO_CLIENT.getMcTypeCode())) {
                    mcListInfoBeanList1 = mcListInfoBeanList1.stream().filter(item -> item.getMcType().equals(queryMcListInfoRequest.getMcType())).collect(Collectors.toList());
                }
                if (null != queryMcListInfoRequest.getMcStatus() && queryMcListInfoRequest.getMcStatus().equals(McStatusEnum.ALL_ENDED.getMcStatusCode())) {
                    mcListInfoBeanList1 = mcListInfoBeanList1.stream().filter(item -> item.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode()) || item.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode())).collect(Collectors.toList());
                }
                mcListInfoBeanList.addAll(mcListInfoBeanList1);
            }

        } catch (Exception e) {
            rglog.error("获取营销活动列表信息失败!");
            throw new BizException(RespCodeEnum.GET_MC_LIST_ERROR.getRespCode(), RespCodeEnum.GET_MC_LIST_ERROR.getRespDesc());
        }
    }

    /**
     * 银行发布员查询营销活动列表数据
     *
     * @param queryMcListInfoRequest 营销活动列表查询接口请求对象
     * @param mcListInfoBeanList     营销活动列表信息
     * @author Jinan Liu
     * @date 2020/6/16 20:49
     */
    private void selectToClientMcListInfoByBankPublishRole(QueryMcListInfoRequest queryMcListInfoRequest, List<McListInfoBean> mcListInfoBeanList) {

        try {

            MoMcListInfoInObj moMcListInfoInObj = (MoMcListInfoInObj) setupDatabaseInputObject(queryMcListInfoRequest, McTypeEnum.MC_TYPE_MO.getMcTypeCode());
            CpMcListInfoInObj cpMcListInfoInObj = (CpMcListInfoInObj) setupDatabaseInputObject(queryMcListInfoRequest, McTypeEnum.MC_TYPE_CP.getMcTypeCode());

            /* 机构编号 */
            if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getQueryOrgId())) {
                moMcListInfoInObj.setOrgId(queryMcListInfoRequest.getQueryOrgId());
                cpMcListInfoInObj.setOrgId(queryMcListInfoRequest.getQueryOrgId());
            }
            if (!StringUtil.isNullorEmpty(globalStartTime)) {
                moMcListInfoInObj.setStartTime(globalStartTime);
                cpMcListInfoInObj.setStartTime(globalStartTime);
            }
            if (!StringUtil.isNullorEmpty(globalEndTime)) {
                moMcListInfoInObj.setEndTime(globalEndTime);
                cpMcListInfoInObj.setEndTime(globalEndTime);
            }
            if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getCreateBy())) {
                moMcListInfoInObj.setOprId(queryMcListInfoRequest.getCreateBy());
                cpMcListInfoInObj.setOprId(queryMcListInfoRequest.getCreateBy());
            }
            /* 查询减免类营销活动数据 */
            McInfoListMapper mcInfoListMapper = new McInfoListMapperImpl();
            List<MoMcListInfoOutObj> moMcListInfoOutObjList = mcInfoListMapper.selectMoneyOffMcListInfoByBankPublishRole(moMcListInfoInObj);
            if (null != moMcListInfoOutObjList) {
                List<McListInfoBean> mcListInfoBeanList1 = moMcListInfoOutObjList.stream().map(this::convertMoneyOffMcListInfo).collect(Collectors.toList());
                if (null != mcName) {
                    mcListInfoBeanList1 = mcListInfoBeanList1.stream().filter(item -> item.getMcName().contains(mcName)).collect(Collectors.toList());
                }
                if (null != queryMcListInfoRequest.getMcType() && !queryMcListInfoRequest.getMcType().equals(McTypeEnum.TO_CLIENT.getMcTypeCode())) {
                    mcListInfoBeanList1 = mcListInfoBeanList1.stream().filter(item -> item.getMcType().equals(queryMcListInfoRequest.getMcType())).collect(Collectors.toList());
                }
                mcListInfoBeanList.addAll(mcListInfoBeanList1);
            }

            /* 查询卡券类营销活动数据 */
            List<CpMcListInfoOutObj> cpMcListInfoOutObjList = mcInfoListMapper.selectCouponMcListInfoByBankPublishRole(cpMcListInfoInObj);
            if (null != cpMcListInfoOutObjList) {
                List<McListInfoBean> mcListInfoBeanList1 = cpMcListInfoOutObjList.stream().map(this::convertCouponMcListInfo).collect(Collectors.toList());
                if (null != mcName) {
                    mcListInfoBeanList1 = mcListInfoBeanList1.stream().filter(item -> item.getMcName().contains(mcName)).collect(Collectors.toList());
                }
                if (null != queryMcListInfoRequest.getMcType() && !queryMcListInfoRequest.getMcType().equals(McTypeEnum.TO_CLIENT.getMcTypeCode())) {
                    mcListInfoBeanList1 = mcListInfoBeanList1.stream().filter(item -> item.getMcType().equals(queryMcListInfoRequest.getMcType())).collect(Collectors.toList());
                }
                mcListInfoBeanList.addAll(mcListInfoBeanList1);
            }
            if (null != mcListInfoBeanList && !StringUtil.isNullorEmpty(queryMcListInfoRequest.getMcStatus()) && queryMcListInfoRequest.getMcStatus().equals(McStatusEnum.ALL_ENDED.getMcStatusCode())) {
                mcListInfoBeanList = mcListInfoBeanList.stream().filter(item -> item.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode()) || item.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode())).collect(Collectors.toList());
            }
        } catch (Exception e) {
            rglog.error("获取营销活动列表信息失败!");
            throw new BizException(RespCodeEnum.GET_MC_LIST_ERROR.getRespCode(), RespCodeEnum.GET_MC_LIST_ERROR.getRespDesc());
        }
    }

    /**
     * 商户查询营销活动列表数据
     *
     * @param queryMcListInfoRequest 营销活动列表查询接口请求对象
     * @param mcListInfoBeanList     营销活动列表信息
     * @author Jinan Liu
     * @date 2020/6/16 21:34
     */
    private void queryToClientMcListInfoByMchnt(QueryMcListInfoRequest queryMcListInfoRequest, List<McListInfoBean> mcListInfoBeanList) {

        try {
            /* 根据商户编号查询商圈编号 */
            String instId = queryMcListInfoRequest.getHeader().getInstId();
            String mchntNo = queryMcListInfoRequest.getQueryId();
            String mchntArea = null;
            TBMchntBaseInfo tbMchntBaseInfo = null;
            MchntInfoMapper mchntInfoMapper = new MchntInfoMapperImpl();
            McInfoListMapper mcInfoListMapper = new McInfoListMapperImpl();

            // 营销活动 mcType＝＝1 只查询 卡卷类
            if (McTypeEnum.MC_TYPE_CP.getMcTypeCode().equals(globalMcType)) {
                CpMcListInfoInObj cpMcListInfoInObj = (CpMcListInfoInObj) setupDatabaseInputObject(queryMcListInfoRequest, McTypeEnum.MC_TYPE_CP.getMcTypeCode());

                if (!StringUtil.isNullorEmpty(mchntNo)) {
                    /* 查询商户基本信息表 */
                    tbMchntBaseInfo = mchntInfoMapper.selectMompMchntBaseInfoByPrimaryKey(instId, mchntNo);
                    if (null == tbMchntBaseInfo) {
                        rglog.error("查询法人机构<{}>商户<{}>基本信息失败!", instId, mchntNo);
                        throw new BizException(RespCodeEnum.NO_TRANS_RECORD.getRespCode(), RespCodeEnum.NO_TRANS_RECORD.getRespDesc());
                    } else {
                        /* 商户编号 */
                        if (!StringUtil.isNullorEmpty(mchntNo)) {
                            cpMcListInfoInObj.setMchntNo(mchntNo);
                        }

                        /* 商圈编号 */
                        mchntArea = tbMchntBaseInfo.getMchntArea();
                        if (!StringUtil.isNullorEmpty(mchntArea)) {
                            cpMcListInfoInObj.setMchntArea(mchntArea);
                        }
                    }
                }
                rglog.debug("INST_ID=<{}>, MCHNT_NO=<{}>", cpMcListInfoInObj.getInstId(), cpMcListInfoInObj.getMchntNo());

                /* 查询卡券类营销活动数据 */
                List<CpMcListInfoOutObj> cpMcListInfoOutObjList = null;
                if (StringUtil.isNullorEmpty(mchntArea)) {
                    cpMcListInfoOutObjList = mcInfoListMapper.selectCouponMcListInfoByMchnt(cpMcListInfoInObj);
                } else {
                    cpMcListInfoOutObjList = mcInfoListMapper.selectCouponMcListInfoByMchntWithArea(cpMcListInfoInObj);
                }
                if (cpMcListInfoOutObjList != null && !cpMcListInfoOutObjList.isEmpty()) {
                    List<McListInfoBean> mcListInfoBeanList1 = cpMcListInfoOutObjList.stream().map(this::convertCouponMcListInfo).collect(Collectors.toList());
                    //商户服务查询  不返回银行全资 银商联合未发布 草稿状态的 不予返回
                    //取出银行全资 进行中 已暂停 测试中 强制结束 自然结束状态的活动
                    List<McListInfoBean> mcListInfoBeanList2 = mcListInfoBeanList1.stream().filter(item -> item.getSponsor().equals(CommonConstant.SPONSOR_BANK)
                            && (item.getMcStatus().equals(McStatusEnum.PROGRESSING.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.PAUSED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.TESTING.getMcStatusCode()))).collect(Collectors.toList());
                    //取出银商联合 进行中 已暂停 测试中 强制结束 自然结束状态的活动
                    List<McListInfoBean> mcListInfoBeanList3 = mcListInfoBeanList1.stream().filter(item -> item.getSponsor().equals(CommonConstant.SPONSOR_MIXED)
                            && (item.getMcStatus().equals(McStatusEnum.PROGRESSING.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.PAUSED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.TESTING.getMcStatusCode()))).collect(Collectors.toList());
                    //取出商户全资免充值（内管平台创建活动） 未发布 草稿状态的活动
                    List<McListInfoBean> mcListInfoBeanList4 = mcListInfoBeanList1.stream().filter(item -> item.getSponsor().equals(CommonConstant.SPONSOR_MCHNT_NORECHARGE)
                            && (item.getMcStatus().equals(McStatusEnum.PROGRESSING.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.PAUSED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.TESTING.getMcStatusCode()))).collect(Collectors.toList());
                    //取出商户全资所有状态的数据
                    List<McListInfoBean> mcListInfoBeanList5 = mcListInfoBeanList1.stream().filter(item -> item.getSponsor().equals(CommonConstant.SPONSOR_MCHNT)).collect(Collectors.toList());

                    mcListInfoBeanList.addAll(mcListInfoBeanList2);
                    mcListInfoBeanList.addAll(mcListInfoBeanList3);
                    mcListInfoBeanList.addAll(mcListInfoBeanList4);
                    mcListInfoBeanList.addAll(mcListInfoBeanList5);
                }

            }

            // 都查
            else {
                MoMcListInfoInObj moMcListInfoInObj = (MoMcListInfoInObj) setupDatabaseInputObject(queryMcListInfoRequest, McTypeEnum.MC_TYPE_MO.getMcTypeCode());
                CpMcListInfoInObj cpMcListInfoInObj = (CpMcListInfoInObj) setupDatabaseInputObject(queryMcListInfoRequest, McTypeEnum.MC_TYPE_CP.getMcTypeCode());
                if (!StringUtil.isNullorEmpty(mchntNo)) {
                    /* 查询商户基本信息表 */
                    tbMchntBaseInfo = mchntInfoMapper.selectMompMchntBaseInfoByPrimaryKey(instId, mchntNo);
                    if (null == tbMchntBaseInfo) {
                        rglog.error("查询法人机构<{}>商户<{}>基本信息失败!", instId, mchntNo);
                        throw new BizException(RespCodeEnum.NO_TRANS_RECORD.getRespCode(), RespCodeEnum.NO_TRANS_RECORD.getRespDesc());
                    } else {
                        /* 商户编号 */
                        if (!StringUtil.isNullorEmpty(mchntNo)) {
                            moMcListInfoInObj.setMchntNo(mchntNo);
                            cpMcListInfoInObj.setMchntNo(mchntNo);
                        }

                        /* 商圈编号 */
                        mchntArea = tbMchntBaseInfo.getMchntArea();
                        if (!StringUtil.isNullorEmpty(mchntArea)) {
                            moMcListInfoInObj.setMchntArea(mchntArea);
                            cpMcListInfoInObj.setMchntArea(mchntArea);
                        }
                    }
                }

                rglog.debug("INST_ID=<{}>, MCHNT_NO=<{}>", moMcListInfoInObj.getInstId(), moMcListInfoInObj.getMchntNo());
                rglog.debug("INST_ID=<{}>, MCHNT_NO=<{}>", cpMcListInfoInObj.getInstId(), cpMcListInfoInObj.getMchntNo());

                /* 查询减免类营销活动数据 */
                List<MoMcListInfoOutObj> moMcListInfoOutObjList = null;
                if (StringUtil.isNullorEmpty(mchntArea)) {
                    moMcListInfoOutObjList = mcInfoListMapper.selectMoneyOffMcListInfoByMchnt(moMcListInfoInObj);
                } else {
                    moMcListInfoOutObjList = mcInfoListMapper.selectMoneyOffMcListInfoByMchntWithArea(moMcListInfoInObj);
                }
                if (moMcListInfoOutObjList != null && !moMcListInfoOutObjList.isEmpty()) {
                    List<McListInfoBean> mcListInfoBeanList1 = moMcListInfoOutObjList.stream().map(this::convertMoneyOffMcListInfo).collect(Collectors.toList());
                    //商户服务查询  不返回银行全资 银商联合未发布 草稿状态的 不予返回
                    //取出银行全资 进行中 已暂停 测试中 强制结束 自然结束状态的活动
                    List<McListInfoBean> mcListInfoBeanList2 = mcListInfoBeanList1.stream().filter(item -> item.getSponsor().equals(CommonConstant.SPONSOR_BANK)
                            && (item.getMcStatus().equals(McStatusEnum.PROGRESSING.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.PAUSED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.TESTING.getMcStatusCode()))).collect(Collectors.toList());
                    //取出银商联合 进行中 已暂停 测试中 强制结束 自然结束状态的活动
                    List<McListInfoBean> mcListInfoBeanList3 = mcListInfoBeanList1.stream().filter(item -> item.getSponsor().equals(CommonConstant.SPONSOR_MIXED)
                            && (item.getMcStatus().equals(McStatusEnum.PROGRESSING.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.PAUSED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.TESTING.getMcStatusCode()))).collect(Collectors.toList());
                    //取出商户全资免充值（内管平台创建活动） 未发布 草稿状态的活动
                    List<McListInfoBean> mcListInfoBeanList4 = mcListInfoBeanList1.stream().filter(item -> item.getSponsor().equals(CommonConstant.SPONSOR_MCHNT_NORECHARGE)
                            && (item.getMcStatus().equals(McStatusEnum.PROGRESSING.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.PAUSED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.TESTING.getMcStatusCode()))).collect(Collectors.toList());
                    //取出商户全资所有状态的数据
                    List<McListInfoBean> mcListInfoBeanList5 = mcListInfoBeanList1.stream().filter(item -> item.getSponsor().equals(CommonConstant.SPONSOR_MCHNT)).collect(Collectors.toList());

                    mcListInfoBeanList.addAll(mcListInfoBeanList2);
                    mcListInfoBeanList.addAll(mcListInfoBeanList3);
                    mcListInfoBeanList.addAll(mcListInfoBeanList4);
                    mcListInfoBeanList.addAll(mcListInfoBeanList5);
                }

                /* 查询卡券类营销活动数据 */
                List<CpMcListInfoOutObj> cpMcListInfoOutObjList = null;
                if (StringUtil.isNullorEmpty(mchntArea)) {
                    cpMcListInfoOutObjList = mcInfoListMapper.selectCouponMcListInfoByMchnt(cpMcListInfoInObj);
                } else {
                    cpMcListInfoOutObjList = mcInfoListMapper.selectCouponMcListInfoByMchntWithArea(cpMcListInfoInObj);
                }
                if (cpMcListInfoOutObjList != null && !cpMcListInfoOutObjList.isEmpty()) {
                    List<McListInfoBean> mcListInfoBeanList1 = cpMcListInfoOutObjList.stream().map(this::convertCouponMcListInfo).collect(Collectors.toList());
                    //商户服务查询  不返回银行全资 银商联合未发布 草稿状态的 不予返回
                    //取出银行全资 进行中 已暂停 测试中 强制结束 自然结束状态的活动
                    List<McListInfoBean> mcListInfoBeanList2 = mcListInfoBeanList1.stream().filter(item -> item.getSponsor().equals(CommonConstant.SPONSOR_BANK)
                            && (item.getMcStatus().equals(McStatusEnum.PROGRESSING.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.PAUSED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.TESTING.getMcStatusCode()))).collect(Collectors.toList());
                    //取出银商联合 进行中 已暂停 测试中 强制结束 自然结束状态的活动
                    List<McListInfoBean> mcListInfoBeanList3 = mcListInfoBeanList1.stream().filter(item -> item.getSponsor().equals(CommonConstant.SPONSOR_MIXED)
                            && (item.getMcStatus().equals(McStatusEnum.PROGRESSING.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.PAUSED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.TESTING.getMcStatusCode()))).collect(Collectors.toList());
                    //取出商户全资免充值（内管平台创建活动） 未发布 草稿状态的活动
                    List<McListInfoBean> mcListInfoBeanList4 = mcListInfoBeanList1.stream().filter(item -> item.getSponsor().equals(CommonConstant.SPONSOR_MCHNT_NORECHARGE)
                            && (item.getMcStatus().equals(McStatusEnum.PROGRESSING.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.PAUSED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode())
                            || item.getMcStatus().equals(McStatusEnum.TESTING.getMcStatusCode()))).collect(Collectors.toList());
                    //取出商户全资所有状态的数据
                    List<McListInfoBean> mcListInfoBeanList5 = mcListInfoBeanList1.stream().filter(item -> item.getSponsor().equals(CommonConstant.SPONSOR_MCHNT)).collect(Collectors.toList());

                    mcListInfoBeanList.addAll(mcListInfoBeanList2);
                    mcListInfoBeanList.addAll(mcListInfoBeanList3);
                    mcListInfoBeanList.addAll(mcListInfoBeanList4);
                    mcListInfoBeanList.addAll(mcListInfoBeanList5);
                }
            }


        } catch (Exception e) {
            rglog.error("获取营销活动列表信息失败!");
            throw new BizException(RespCodeEnum.GET_MC_LIST_ERROR.getRespCode(), RespCodeEnum.GET_MC_LIST_ERROR.getRespDesc());
        }

    }

    /**
     * 使用营销活动类型查询营销活动列表临时数据
     *
     * @param queryMcListInfoRequest 营销活动列表查询接口请求对象
     * @param mcListInfoBeanList     营销活动列表查询接口应答对象
     * @param mcType                 营销活动类型
     * @throws BizException 异常信息
     * @author Jinan Liu
     * @date 2020/4/1 10:13
     */
    private void selectAllTmpMcListInfoByBankAuditRole(QueryMcListInfoRequest queryMcListInfoRequest, List<McListInfoBean> mcListInfoBeanList, String mcType) throws BizException {

        /* 银行审批员查询所有待审批营销活动数据 */
        getTmpMcListInfoByTableName(queryMcListInfoRequest, mcListInfoBeanList, TableNameEnum.T_M_MC_APS_INFO.getTableNameCode());
        getTmpMcListInfoByTableName(queryMcListInfoRequest, mcListInfoBeanList, TableNameEnum.T_M_MC_CCB_INFO.getTableNameCode());
        getTmpMcListInfoByTableName(queryMcListInfoRequest, mcListInfoBeanList, TableNameEnum.T_M_MC_CP_INFO.getTableNameCode());
        getTmpMcListInfoByTableName(queryMcListInfoRequest, mcListInfoBeanList, TableNameEnum.T_M_MC_MFD_INFO.getTableNameCode());
        getTmpMcListInfoByTableName(queryMcListInfoRequest, mcListInfoBeanList, TableNameEnum.T_M_MC_MO_INFO.getTableNameCode());
    }

    /**
     * 使用表名查询营销活动列表临时数据
     *
     * @param queryMcListInfoRequest 营销活动列表查询接口请求对象
     * @param mcListInfoBeanList     营销活动列表查询接口应答对象
     * @param tableName              数据库表名
     * @throws BizException 异常信息
     * @author Jinan Liu
     * @date 2020/4/1 10:13
     */
    private void getTmpMcListInfoByTableName(QueryMcListInfoRequest queryMcListInfoRequest, List<McListInfoBean> mcListInfoBeanList, String tableName) throws BizException {

        try {

            TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();
            if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getHeader().getInstId())) {
                tmPlatBizTmp.setInstId(queryMcListInfoRequest.getHeader().getInstId());
            }
            if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getQueryOrgId())) {
                tmPlatBizTmp.setOrgId(queryMcListInfoRequest.getQueryOrgId());
            }
            if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getMcNo())) {
                tmPlatBizTmp.setMcNo(queryMcListInfoRequest.getMcNo());
            }
            if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getMcStatus())) {
                tmPlatBizTmp.setMcStatus(queryMcListInfoRequest.getMcStatus());
            }
            if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getAuditStatus())) {
                tmPlatBizTmp.setAuditStatus(queryMcListInfoRequest.getAuditStatus());
            }
            if (!StringUtil.isNullorEmpty(tableName)) {
                tmPlatBizTmp.setOprTableEname(tableName);
            }
            if (!StringUtil.isNullorEmpty(globalStartTime)) {
                tmPlatBizTmp.setStartTime(globalStartTime);
                tmPlatBizTmp.setStartTime(globalStartTime);
            }
            if (!StringUtil.isNullorEmpty(globalEndTime)) {
                tmPlatBizTmp.setEndTime(globalEndTime);
                tmPlatBizTmp.setEndTime(globalEndTime);
            }
            if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getCreateBy())) {
                tmPlatBizTmp.setOprId(queryMcListInfoRequest.getCreateBy());
            }

            PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
            List<TMPlatBizTmp> objectList = platBizTmpMapper.selectTmpMcListInfo(tmPlatBizTmp);
            if (null != objectList && !objectList.isEmpty()) {
                List<McListInfoBean> mcListInfoBeanList1 = objectList.stream().map(this::convertTmpMcInfo).collect(Collectors.toList());
                if (null != queryMcListInfoRequest.getMcType() && !queryMcListInfoRequest.getMcType().equals(McTypeEnum.ALL_MC_TYPE.getMcTypeCode())) {
                    mcListInfoBeanList1 = mcListInfoBeanList1.stream().filter(item -> item.getMcType().equals(queryMcListInfoRequest.getMcType())).collect(Collectors.toList());
                }
                if (null != queryMcListInfoRequest.getMcName()) {
                    mcListInfoBeanList1 = mcListInfoBeanList1.stream().filter(item -> item.getMcName().contains(queryMcListInfoRequest.getMcName())).collect(Collectors.toList());
                }
                mcListInfoBeanList.addAll(mcListInfoBeanList1);
            }
        } catch (Exception e) {
            rglog.error("根据查询条件获取营销活动列表临时数据失败!");
            throw new BizException(RespCodeEnum.GET_TMP_MC_LIST_ERROR.getRespCode(), RespCodeEnum.GET_TMP_MC_LIST_ERROR.getRespDesc());
        }
    }

    /**
     * 减免类营销活动实体类转换
     *
     * @param moMcListInfoOutObj 减免类营销活动列表查询使用实体类出参
     * @return cc.rengu.igas.momp.facade.bean.McListInfoBean 营销活动列表查询接口应答对象
     * @author Jinan Liu
     * @date 2020/6/16 20:28
     */
    private McListInfoBean convertMoneyOffMcListInfo(MoMcListInfoOutObj moMcListInfoOutObj) {

        McListInfoBean mcListInfoBean = new McListInfoBean();

        try {

            /* 营销活动编号 */
            mcListInfoBean.setMcNo(moMcListInfoOutObj.getMcNo());
            /* 营销活动名称 */
            mcListInfoBean.setMcName(moMcListInfoOutObj.getMcName());
            /* 营销活动状态 */
            mcListInfoBean.setMcStatus(moMcListInfoOutObj.getMcStatus());
            /* 营销活动类型 */
            mcListInfoBean.setMcType(moMcListInfoOutObj.getMcType());
            /* 活动起始日期 */
            mcListInfoBean.setMcStartDate(moMcListInfoOutObj.getMcStartDate());
            /* 活动截止日期 */
            mcListInfoBean.setMcEndDate(moMcListInfoOutObj.getMcEndDate());
            /* 活动结束日期 */
            mcListInfoBean.setMcActualEndDate(moMcListInfoOutObj.getMcActualEndDate());
            /* 出资方 */
            String sponsor = null;
            if (!StringUtil.isNullorEmpty(moMcListInfoOutObj.getSponsor())) {
                sponsor = moMcListInfoOutObj.getSponsor();
                mcListInfoBean.setSponsor(moMcListInfoOutObj.getSponsor());
            }
            /* 活动预算 */
            mcListInfoBean.setBudget(moMcListInfoOutObj.getBudget());
            /* 已消耗预算 */
            if (StringUtil.isNullorEmpty(moMcListInfoOutObj.getTotalAmtAcc())) {
                mcListInfoBean.setBudgetUsed(CommonConstant.ZERO_AMOUNT);
            } else {
                mcListInfoBean.setBudgetUsed(moMcListInfoOutObj.getTotalAmtAcc());
            }
            /* 审批状态 */
            mcListInfoBean.setAuditStatus(moMcListInfoOutObj.getAuditStatus());
            /* 创建人 */
            mcListInfoBean.setOprId(moMcListInfoOutObj.getOprId());
            /* 创建时间 */
            mcListInfoBean.setCreateTime(moMcListInfoOutObj.getCreateTime());
            /* 最后修改人 */
            mcListInfoBean.setLastOprId(moMcListInfoOutObj.getLastOprId());
            /* 修改时间 */
            mcListInfoBean.setUpdateTime(moMcListInfoOutObj.getUpdateTime());
            if (queryType.equals(QueryTypeEnum.MCHNT_QYERY_TYPE.getQueryTypeCode())) {
                /* 查询主体参加活动标志 */
                if (StringUtil.isNullorEmpty(sponsor)) {
                    /* 无法区分商户是否参与联合营销活动 */
                    mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_DEFAULT);
                } else {
                    if (CommonConstant.SPONSOR_MIXED.equals(sponsor)) {
                        /* 联合营销活动的特殊处理步骤 */
                        String newMchntFlag = moMcListInfoOutObj.getNewMchntFlag();
                        String exitFlag = moMcListInfoOutObj.getExitFlag();
                        if (CommonConstant.MCHNT_OLD_FLAG.equals(newMchntFlag) && CommonConstant.MC_EXIT_FLAG.equals(exitFlag)) {
                            /* 商户暂未参与联合营销活动 */
                            mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_NO);
                        } else if (CommonConstant.MCHNT_NEW_FLAG.equals(newMchntFlag) && CommonConstant.MC_NOT_EXIT_FLAG.equals(exitFlag)) {
                            /* 商户已参与联合营销活动 */
                            mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_YES);
                        } else {
                            /* 无法区分商户是否参与联合营销活动 */
                            mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_DEFAULT);
                        }
                    } else {
                        /* 银行全资或商户全资默认参与 */
                        mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_YES);
                    }
                }
            } else {
                List<TMMcOrgInfo> newList = tmMcOrgInfoList.stream().filter(item -> item.getOrgId().equals(moMcListInfoOutObj.getCrtOrgId())).collect(Collectors.toList());
                if (null != newList && newList.size() > 0) {
                    /* 已参与营销活动 */
                    mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_YES);
                } else {
                    /* 未参与营销活动 */
                    mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_NO);
                }
                //如果是商户独资的活动则不允许修改
                if (moMcListInfoOutObj.getSponsor().equals(CommonConstant.SPONSOR_MCHNT)) {
                    mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_SOLE);
                }
            }
            //排序
            //进行中排1
            if (moMcListInfoOutObj.getMcStatus().equals(McStatusEnum.PROGRESSING.getMcStatusCode())) {
                mcListInfoBean.setMcStatusSort(1);
                //草稿排2
            } else if (moMcListInfoOutObj.getMcStatus().equals(McStatusEnum.DRAFT.getMcStatusCode())) {
                mcListInfoBean.setMcStatusSort(2);
                //已暂停排3
            } else if (moMcListInfoOutObj.getMcStatus().equals(McStatusEnum.PAUSED.getMcStatusCode())) {
                mcListInfoBean.setMcStatusSort(3);
                //未发布排4
            } else if (moMcListInfoOutObj.getMcStatus().equals(McStatusEnum.NOT_PUBLISHED.getMcStatusCode())) {
                mcListInfoBean.setMcStatusSort(4);
                //自然结束排5
            } else if (moMcListInfoOutObj.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode())) {
                mcListInfoBean.setMcStatusSort(5);
            } else {
                //其他排6
                mcListInfoBean.setMcStatusSort(6);
            }
        } catch (Exception e) {
            rglog.error("转换营销活动信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcListInfoBean;
    }

    /**
     * 卡券类营销活动实体类转换
     *
     * @param cpMcListInfoOutObj 卡券类营销活动列表查询使用实体类出参
     * @return cc.rengu.igas.momp.facade.bean.McListInfoBean 营销活动列表查询接口应答对象
     * @author Jinan Liu
     * @date 2020/6/16 20:35
     */
    private McListInfoBean convertCouponMcListInfo(CpMcListInfoOutObj cpMcListInfoOutObj) {

        McListInfoBean mcListInfoBean = new McListInfoBean();

        try {

            /* 营销活动编号 */
            mcListInfoBean.setMcNo(cpMcListInfoOutObj.getMcNo());
            /* 营销活动名称 */
            mcListInfoBean.setMcName(cpMcListInfoOutObj.getMcName());
            /* 营销活动状态 */
            mcListInfoBean.setMcStatus(cpMcListInfoOutObj.getMcStatus());
            /* 营销活动类型 */
            mcListInfoBean.setMcType(cpMcListInfoOutObj.getMcType());
            /* 活动起始日期 */
            mcListInfoBean.setMcStartDate(cpMcListInfoOutObj.getMcStartDate());
            /* 活动截止日期 */
            mcListInfoBean.setMcEndDate(cpMcListInfoOutObj.getMcEndDate());
            /* 活动结束日期 */
            mcListInfoBean.setMcActualEndDate(cpMcListInfoOutObj.getMcActualEndDate());
            /* 出资方 */
            String sponsor = null;
            if (!StringUtil.isNullorEmpty(cpMcListInfoOutObj.getSponsor())) {
                sponsor = cpMcListInfoOutObj.getSponsor();
                mcListInfoBean.setSponsor(cpMcListInfoOutObj.getSponsor());
            }
            /* 活动预算 */
            mcListInfoBean.setBudget(cpMcListInfoOutObj.getBudget());
            /* 已消耗预算 */
            if (StringUtil.isNullorEmpty(cpMcListInfoOutObj.getTotalAmtAcc())) {
                mcListInfoBean.setBudgetUsed(CommonConstant.ZERO_AMOUNT);
            } else {
                mcListInfoBean.setBudgetUsed(cpMcListInfoOutObj.getTotalAmtAcc());
            }
            /* 审批状态 */
            mcListInfoBean.setAuditStatus(cpMcListInfoOutObj.getAuditStatus());
            /* 创建人 */
            mcListInfoBean.setOprId(cpMcListInfoOutObj.getOprId());
            /* 创建时间 */
            mcListInfoBean.setCreateTime(cpMcListInfoOutObj.getCreateTime());
            /* 最后修改人 */
            mcListInfoBean.setLastOprId(cpMcListInfoOutObj.getLastOprId());
            /* 修改时间 */
            mcListInfoBean.setUpdateTime(cpMcListInfoOutObj.getUpdateTime());

            //查询类型是 商户
            if (queryType.equals(QueryTypeEnum.MCHNT_QYERY_TYPE.getQueryTypeCode())) {
                /* 查询主体参加活动标志 */
                if (StringUtil.isNullorEmpty(sponsor)) {
                    /* 无法区分商户是否参与联合营销活动 */
                    mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_DEFAULT);
                } else {
                    if (CommonConstant.SPONSOR_MIXED.equals(sponsor)) {
                        /* 联合营销活动的特殊处理步骤 */
                        String newMchntFlag = cpMcListInfoOutObj.getNewMchntFlag();
                        String exitFlag = cpMcListInfoOutObj.getExitFlag();
                        if (CommonConstant.MCHNT_OLD_FLAG.equals(newMchntFlag) && CommonConstant.MC_EXIT_FLAG.equals(exitFlag)) {
                            /* 商户暂未参与联合营销活动 */
                            mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_NO);
                        } else if (CommonConstant.MCHNT_NEW_FLAG.equals(newMchntFlag) && CommonConstant.MC_NOT_EXIT_FLAG.equals(exitFlag)) {
                            /* 商户已参与联合营销活动 */
                            mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_YES);
                        } else {
                            /* 无法区分商户是否参与联合营销活动 */
                            mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_DEFAULT);
                        }
                    } else {
                        /* 银行全资或商户全资默认参与 */
                        mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_YES);
                    }
                }

                // 营销活动类型是1     －》 营销活动大类-卡券类 MC_TYPE_CP("1"), 就 去查卡券数量
                if (McTypeEnum.MC_TYPE_CP.getMcTypeCode().equals(globalMcType)) {
                    //查询 卡券已领取张数
                    int couponClaimedCount = selectTMCouponClaimedCount(cpMcListInfoOutObj.getInstId(), cpMcListInfoOutObj.getMcNo());
                    //查询 卡券已核销张数
                    int couponRedeemedCount = selectTMCouponRedeemedCount(cpMcListInfoOutObj.getInstId(), cpMcListInfoOutObj.getMcNo());

                    if (null != cpMcListInfoOutObj.getCouponInventory()) {
                        /*卡券库存*/
                        mcListInfoBean.setCouponInventory(Integer.parseInt(cpMcListInfoOutObj.getCouponInventory()));
                    } else {
                        /*卡券库存*/
                        mcListInfoBean.setCouponInventory(CommonConstant.ZERO);
                    }
                    /*卡券已领取张数*/
                    mcListInfoBean.setCouponClaimed(couponClaimedCount);
                    /*卡券已核销张数*/
                    mcListInfoBean.setCouponRedeemed(couponRedeemedCount);

                }

            } else {
                List<TMMcOrgInfo> newList = tmMcOrgInfoList.stream().filter(item -> item.getOrgId().equals(cpMcListInfoOutObj.getCrtOrgId())).collect(Collectors.toList());
                if (null != newList && newList.size() > 0) {
                    /* 已参与营销活动 */
                    mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_YES);
                } else {
                    /* 未参与营销活动 */
                    mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_NO);
                }
                //如果是商户独资的活动则不允许修改
                if (cpMcListInfoOutObj.getSponsor().equals(CommonConstant.SPONSOR_MCHNT)) {
                    mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_SOLE);
                }
            }
            //排序
            //进行中排1
            if (cpMcListInfoOutObj.getMcStatus().equals(McStatusEnum.PROGRESSING.getMcStatusCode())) {
                mcListInfoBean.setMcStatusSort(1);
                //草稿排2
            } else if (cpMcListInfoOutObj.getMcStatus().equals(McStatusEnum.DRAFT.getMcStatusCode())) {
                mcListInfoBean.setMcStatusSort(2);
                //已暂停排3
            } else if (cpMcListInfoOutObj.getMcStatus().equals(McStatusEnum.PAUSED.getMcStatusCode())) {
                mcListInfoBean.setMcStatusSort(3);
                //未发布排4
            } else if (cpMcListInfoOutObj.getMcStatus().equals(McStatusEnum.NOT_PUBLISHED.getMcStatusCode())) {
                mcListInfoBean.setMcStatusSort(4);
                //自然结束排5
            } else if (cpMcListInfoOutObj.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode())) {
                mcListInfoBean.setMcStatusSort(5);
            } else {
                //其他排6
                mcListInfoBean.setMcStatusSort(6);
            }
        } catch (Exception e) {
            rglog.error("转换营销活动信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcListInfoBean;
    }

    /**
     * 查询 卡已核销张数
     * (注： 2-已核销(最终状态))
     *
     * @param instId 机构编码
     * @param mcNo   营销活动编号
     * @return int 卡券数量
     * @author liujinan
     * @date 2020-09-23 16:56:28
     */
    private int selectTMCouponRedeemedCount(String instId, String mcNo) throws Exception {
        CouponInfoMapper couponInfoMapper = new CouponInfoMapperImpl();
        TMCouponInfo tmCouponInfo = couponInfoMapper.selectTMCouponRedeemedCount(instId, mcNo);
        if (null == tmCouponInfo) {
            return CommonConstant.ZERO;
        } else {
            return Integer.parseInt(tmCouponInfo.getRemark4());
        }
    }

    /**
     * 查询 卡券已领取张数
     * 1-未核销(已领取，未核销)  9 且有领取人 也为已领取
     *
     * @param instId 机构编码
     * @param mcNo   营销活动编号
     * @return int 卡券数量
     * @author liujinan
     * @date 2020-09-23 16:23:48
     */
    private int selectTMCouponClaimedCount(String instId, String mcNo) throws Exception {
        CouponInfoMapper couponInfoMapper = new CouponInfoMapperImpl();
        TMCouponInfo tmCouponInfo = couponInfoMapper.selectTMCouponClaimedCount(instId, mcNo);
        if (null == tmCouponInfo) {
            return CommonConstant.ZERO;
        } else {
            return Integer.parseInt(tmCouponInfo.getRemark4());
        }
    }

    /**
     * 转换换业务数据临时表临时数据
     *
     * @param tmPlatBizTmp 业务数据临时表
     * @return cc.rengu.igas.momp.facade.bean.McListInfoBean
     * @author Jinan Liu
     * @date 2020/3/30 11:57
     */
    private McListInfoBean convertTmpMcInfo(TMPlatBizTmp tmPlatBizTmp) {

        McListInfoBean mcListInfoBean = new McListInfoBean();

        try {

            String mcNo;
            String mcName;
            String mcType;
            String mcStartDate;
            String mcEndDate;
            String mcActualEndDate;
            String budget;
            String sponsor = null;
            String crtOrgId;

            /* 根据营销活动类型解析BIZ_DATA1字段内容 */
            String mcTypeOne = tmPlatBizTmp.getMcNo().substring(2, 3);
            if (McTypeEnum.MC_TYPE_MO.getMcTypeCode().equals(mcTypeOne)) {
                JsonTmpMoMcInfo jsonTmpMoMcInfo = JsonOperation.parseMoMcInfoTmpBizData1(tmPlatBizTmp, rglog);
                mcNo = jsonTmpMoMcInfo.getMcNo();
                mcName = jsonTmpMoMcInfo.getMcName();
                mcType = jsonTmpMoMcInfo.getMcType();
                mcStartDate = jsonTmpMoMcInfo.getMcStartDate();
                mcEndDate = jsonTmpMoMcInfo.getMcEndDate();
                mcActualEndDate = jsonTmpMoMcInfo.getMcActualEndDate();
                sponsor = jsonTmpMoMcInfo.getSponsor();
                budget = jsonTmpMoMcInfo.getBudget();
                crtOrgId = jsonTmpMoMcInfo.getCrtOrgId();
            } else if (McTypeEnum.MC_TYPE_CP.getMcTypeCode().equals(mcTypeOne)) {
                JsonTmpCpMcInfo jsonTmpCpMcInfo = JsonOperation.parseCpMcInfoTmpBizData1(tmPlatBizTmp, rglog);
                mcNo = jsonTmpCpMcInfo.getMcNo();
                mcName = jsonTmpCpMcInfo.getMcName();
                mcType = jsonTmpCpMcInfo.getMcType();
                mcStartDate = jsonTmpCpMcInfo.getMcStartDate();
                mcEndDate = jsonTmpCpMcInfo.getMcEndDate();
                mcActualEndDate = jsonTmpCpMcInfo.getMcActualEndDate();
                sponsor = jsonTmpCpMcInfo.getSponsor();
                budget = jsonTmpCpMcInfo.getBudget();
                crtOrgId = jsonTmpCpMcInfo.getCrtOrgId();

            } else if (McTypeEnum.MC_TYPE_MFD.getMcTypeCode().equals(mcTypeOne)) {
                JsonTmpMfdMcInfo jsonTmpMfdMcInfo = JsonOperation.parseMfdMcInfoTmpBizData1(tmPlatBizTmp, rglog);
                mcNo = jsonTmpMfdMcInfo.getMcNo();
                mcName = jsonTmpMfdMcInfo.getMcName();
                mcType = jsonTmpMfdMcInfo.getMcType();
                mcStartDate = jsonTmpMfdMcInfo.getMcStartDate();
                mcEndDate = jsonTmpMfdMcInfo.getMcEndDate();
                mcActualEndDate = jsonTmpMfdMcInfo.getMcActualEndDate();
                budget = jsonTmpMfdMcInfo.getBudget();
                crtOrgId = jsonTmpMfdMcInfo.getCrtOrgId();

            } else if (McTypeEnum.MC_TYPE_APS.getMcTypeCode().equals(mcTypeOne)) {
                JsonTmpApsMcInfo jsonTmpApsMcInfo = JsonOperation.parseApsMcInfoTmpBizData1(tmPlatBizTmp, rglog);
                mcNo = jsonTmpApsMcInfo.getMcNo();
                mcName = jsonTmpApsMcInfo.getMcName();
                mcType = jsonTmpApsMcInfo.getMcType();
                mcStartDate = jsonTmpApsMcInfo.getMcStartDate();
                mcEndDate = jsonTmpApsMcInfo.getMcEndDate();
                mcActualEndDate = jsonTmpApsMcInfo.getMcActualEndDate();
                budget = jsonTmpApsMcInfo.getBudget();
                crtOrgId = jsonTmpApsMcInfo.getCrtOrgId();

            } else if (McTypeEnum.MC_TYPE_CCB.getMcTypeCode().equals(mcTypeOne)) {
                JsonTmpCcbMcInfo jsonTmpCcbMcInfo = JsonOperation.parseCcbMcInfoTmpBizData1(tmPlatBizTmp, rglog);
                mcNo = jsonTmpCcbMcInfo.getMcNo();
                mcName = jsonTmpCcbMcInfo.getMcName();
                mcType = jsonTmpCcbMcInfo.getMcType();
                mcStartDate = jsonTmpCcbMcInfo.getMcStartDate();
                mcEndDate = jsonTmpCcbMcInfo.getMcEndDate();
                mcActualEndDate = jsonTmpCcbMcInfo.getMcActualEndDate();
                budget = jsonTmpCcbMcInfo.getBudget();
                crtOrgId = jsonTmpCcbMcInfo.getCrtOrgId();

            } else {
                rglog.error("不支持的营销活动类型<{}>,不可转换数据!", mcTypeOne);
                throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
            }

            /* 营销活动编号 */
            mcListInfoBean.setMcNo(mcNo);
            /* 营销活动名称 */
            mcListInfoBean.setMcName(mcName);
            /* 营销活动状态 */
            mcListInfoBean.setMcStatus(tmPlatBizTmp.getMcStatus());
            /* 营销活动类型 */
            mcListInfoBean.setMcType(mcType);
            /* 活动起始日期 */
            mcListInfoBean.setMcStartDate(mcStartDate);
            /* 活动截止日期 */
            mcListInfoBean.setMcEndDate(mcEndDate);
            /* 活动结束日期 */
            mcListInfoBean.setMcActualEndDate(mcActualEndDate);
            /* 出资方 */
            if (!StringUtil.isNullorEmpty(sponsor)) {
                mcListInfoBean.setSponsor(sponsor);
            }
            /* 活动预算 */
            mcListInfoBean.setBudget(budget);
            /* 已消耗预算 */
            mcListInfoBean.setBudgetUsed(CommonConstant.ZERO_AMOUNT);
            /* 审批状态 */
            mcListInfoBean.setAuditStatus(tmPlatBizTmp.getAuditStatus());
            /* 创建人 */
            mcListInfoBean.setOprId(tmPlatBizTmp.getOprId());
            /* 创建时间 */
            mcListInfoBean.setCreateTime(tmPlatBizTmp.getCreateTime());
            /* 最后修改人 */
            mcListInfoBean.setLastOprId(tmPlatBizTmp.getLastOprId());
            if (StringUtil.isNullorEmpty(tmPlatBizTmp.getLastUpdateTime())) {
                /* 修改时间 */
                mcListInfoBean.setUpdateTime(tmPlatBizTmp.getCreateTime());
            } else {
                /* 修改时间 */
                mcListInfoBean.setUpdateTime(tmPlatBizTmp.getLastUpdateTime());
            }
            /* 查询主体参加活动标志 */
            mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_DEFAULT);
            //判断上送操作员机构是否有权限审核数据
            List<TMMcOrgInfo> newList = tmMcOrgInfoList.stream().filter(item -> item.getOrgId().equals(crtOrgId)).collect(Collectors.toList());
            if (null != newList && newList.size() > 0) {
                /* 已参与营销活动 */
                mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_YES);
            } else {
                /* 未参与营销活动 */
                mcListInfoBean.setAttendFlag(CommonConstant.ATTEND_FLAG_NO);
            }

        } catch (Exception e) {
            rglog.error("转换营销活动临时表信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcListInfoBean;
    }

    /**
     * 数据库查询前赋值数据库实体类入参
     *
     * @param queryMcListInfoRequest 营销活动列表查询接口请求对象
     * @param mcType                 营销活动类型
     * @return java.lang.Object 营销活动列表查询使用实体类入参
     * @author Jinan Liu
     * @date 2020/6/16 20:21
     */
    private Object setupDatabaseInputObject(QueryMcListInfoRequest queryMcListInfoRequest, String mcType) {

        if (null != mcType) {
            if (McTypeEnum.MC_TYPE_MO.getMcTypeCode().equals(mcType)) {

                MoMcListInfoInObj moMcListInfoInObj = new MoMcListInfoInObj();

                /* 机构编码 */
                moMcListInfoInObj.setInstId(queryMcListInfoRequest.getHeader().getInstId());

                /* 营销活动编号 */
                if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getMcNo())) {
                    moMcListInfoInObj.setMcNo(queryMcListInfoRequest.getMcNo());
                }

                /* 营销活动名称 */
                if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getMcName())) {
                    moMcListInfoInObj.setMcName(queryMcListInfoRequest.getMcName());
                }

                /* 营销活动类型 */
                if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getMcType())) {
                    if (McTypeEnum.TO_CLIENT.getMcTypeCode().equals(queryMcListInfoRequest.getMcType()) ||
                            McTypeEnum.ALL_MC_TYPE.getMcTypeCode().equals(queryMcListInfoRequest.getMcType())) {
                        rglog.info("查询全类型的营销活动数据,不需要配置营销活动类型! MC_TYPE=<{}>", queryMcListInfoRequest.getMcType());
                    } else {
                        moMcListInfoInObj.setMcType(queryMcListInfoRequest.getMcType());
                    }
                }

                /* 营销活动状态 */
                if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getMcStatus()) && !queryMcListInfoRequest.getMcStatus().equals(McStatusEnum.ALL_ENDED.getMcStatusCode())) {
                    moMcListInfoInObj.setMcStatus(queryMcListInfoRequest.getMcStatus());
                }

                /* 审批状态 */
                if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getAuditStatus())) {
                    moMcListInfoInObj.setAuditStatus(queryMcListInfoRequest.getAuditStatus());
                }

                /* 当前系统日期 */
                if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getHeader().getTransDate())) {
                    moMcListInfoInObj.setTxnDate(queryMcListInfoRequest.getHeader().getTransDate());
                }

                return moMcListInfoInObj;

            } else if (McTypeEnum.MC_TYPE_CP.getMcTypeCode().equals(mcType)) {

                CpMcListInfoInObj cpMcListInfoInObj = new CpMcListInfoInObj();

                /* 机构编码 */
                cpMcListInfoInObj.setInstId(queryMcListInfoRequest.getHeader().getInstId());

                /* 营销活动编号 */
                if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getMcNo())) {
                    cpMcListInfoInObj.setMcNo(queryMcListInfoRequest.getMcNo());
                }

                /* 营销活动名称 */
                if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getMcName())) {
                    cpMcListInfoInObj.setMcName(queryMcListInfoRequest.getMcName());
                }

                /* 营销活动类型 */
                if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getMcType())) {
                    if (McTypeEnum.TO_CLIENT.getMcTypeCode().equals(queryMcListInfoRequest.getMcType()) ||
                            McTypeEnum.ALL_MC_TYPE.getMcTypeCode().equals(queryMcListInfoRequest.getMcType()) ||
                            McTypeEnum.MC_TYPE_CP.getMcTypeCode().equals(queryMcListInfoRequest.getMcType())) {

                        rglog.info("查询全类型的营销活动数据,不需要配置营销活动类型! MC_TYPE=<{}>", queryMcListInfoRequest.getMcType());
                    } else {
                        cpMcListInfoInObj.setMcType(queryMcListInfoRequest.getMcType());
                    }
                }

                /* 营销活动状态 */
                if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getMcStatus()) && !queryMcListInfoRequest.getMcStatus().equals(McStatusEnum.ALL_ENDED.getMcStatusCode())) {
                    cpMcListInfoInObj.setMcStatus(queryMcListInfoRequest.getMcStatus());
                }

                /* 审批状态 */
                if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getAuditStatus())) {
                    cpMcListInfoInObj.setAuditStatus(queryMcListInfoRequest.getAuditStatus());
                }

                /* 当前系统日期 */
                if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getHeader().getTransDate())) {
                    cpMcListInfoInObj.setTxnDate(queryMcListInfoRequest.getHeader().getTransDate());
                }

                return cpMcListInfoInObj;

            } else {
                rglog.error("营销活动类型<{}>为不支持的业务类型!", mcType);
                return null;
            }

        } else {
            rglog.error("营销活动类型为空,不支持的业务!");
            return null;
        }
    }

    /**
     * 报文检查
     *
     * @param queryMcListInfoRequest 营销活动列表查询接口请求对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/7/18 17:53
     */
    private void messageValidation(QueryMcListInfoRequest queryMcListInfoRequest) throws Exception {

        /* 检查交易日期 */
        if (StringUtil.isNullorEmpty(queryMcListInfoRequest.getHeader().getTransDate())) {
            rglog.error("交易日期必须出现!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalTransDate = queryMcListInfoRequest.getHeader().getTransDate();
        }

        /* 检查交易时间 */
        if (StringUtil.isNullorEmpty(queryMcListInfoRequest.getHeader().getTransTime())) {
            rglog.error("交易时间必须出现!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        /* 检查机构标识 */
        if (StringUtil.isNullorEmpty(queryMcListInfoRequest.getHeader().getInstId())) {
            rglog.error("机构标识必须出现!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalInstId = queryMcListInfoRequest.getHeader().getInstId();
        }

        /* 检查交易流水号 */
        if (StringUtil.isNullorEmpty(queryMcListInfoRequest.getHeader().getTraceNo())) {
            rglog.error("交易流水号必须出现!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            globalTraceNo = queryMcListInfoRequest.getHeader().getTraceNo();
        }

        /* 检查查询类型 */
        if (StringUtil.isNullorEmpty(queryMcListInfoRequest.getQueryType())) {
            rglog.error("查询类型必须出现!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        /* 检查查询主体 */
        if (StringUtil.isNullorEmpty(queryMcListInfoRequest.getQueryId())) {
            rglog.error("查询主体必须出现!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        /* 检查查询主体所属机构 */
        if (StringUtil.isNullorEmpty(queryMcListInfoRequest.getQueryOrgId())) {
            rglog.error("查询主体所属机构必须出现!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        /* 检查查询主体角色*/
        if (StringUtil.isNullorEmpty(queryMcListInfoRequest.getQueryRole())) {
            rglog.error("查询主体角色必须出现!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        /* 营销活动类型*/
        if (!StringUtil.isNullorEmpty(queryMcListInfoRequest.getMcType())) {
            globalMcType = queryMcListInfoRequest.getMcType();
        }

        /* 当前页数 */
        if (StringUtil.isNullorEmpty(queryMcListInfoRequest.getPageIndex())) {
            rglog.error("当前页数必须出现!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }

        /* 页显示记录数 */
        if (StringUtil.isNullorEmpty(queryMcListInfoRequest.getPageSize())) {
            rglog.error("页显示记录数必须出现!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 查询活动已经使用的优惠额度值
     *
     * @throws Exception
     * @author liujinan
     * @date 2020/9/16
     */
    private String calToClientAlredyUsedFee(String mcNo, String mcStartDate, String mcType, String mcEndDate, String mcStatus) throws Exception {
        if (McStatusEnum.DRAFT.getMcStatusCode().equals(mcStatus) || McStatusEnum.NOT_PUBLISHED.getMcStatusCode().equals(mcStatus)) {
            rglog.info("活动是草稿或未发布状态，已使用预算直接返回0.00");
            String alredyUse = CommonConstant.ZERO_AMOUNT;
            return alredyUse;
        }
        int batchStatus = CommonConstant.FLAG_NOT_SET;
        String lastDate = DateUtil.getBaseDateOffsetDay(globalTransDate, CommonConstant.MINUS_ONE);
        if (DateUtil.compareDate(lastDate, mcEndDate) > 0) {
            lastDate = mcEndDate;
        }
        String lastSecondDate = DateUtil.getBaseDateOffsetDay(lastDate, CommonConstant.MINUS_ONE);

        //查询对客户营销活动统计表数据
        TMStat2C tmStat2C = selectToClientMcLevelStatistics(globalInstId, mcNo, CommonConstant.ZERO_COMMON_CONSTANT);
        if (null == tmStat2C) {
            rglog.info("机构<{}> 营销活动<{}> 规则<{}> 对客户营销活动统计表无数据!", globalInstId, mcNo, CommonConstant.ZERO_COMMON_CONSTANT);
            tmStat2C = new TMStat2C();
            tmStat2C.setTotalQtyAcc(CommonConstant.ZERO_COMMON_CONSTANT);
            tmStat2C.setTotalAmtAcc(CommonConstant.ZERO_COMMON_CONSTANT);
        }
        //查询对客户营销活动单日统计表数据
        TMStat2CDay tmStat2CDay = selectToClientMcDayStatistics(globalInstId, mcNo, CommonConstant.ZERO_COMMON_CONSTANT, globalTransDate);
        if (null == tmStat2CDay) {
            rglog.error("机构<{}>的减免类营销活动<{}>的规则<{}>对客户营销活动单日统计表数据查询失败!", globalInstId, mcNo, CommonConstant.ZERO_COMMON_CONSTANT);
            //取到0条数据,说明该营销活动还未产生统计值,按所有统计值都是0进行处理
            tmStat2CDay = new TMStat2CDay();
            tmStat2CDay.setTotalAmtAcc(CommonConstant.ZERO_COMMON_CONSTANT);
        }
        String batchDate;
        //查询统计信息备份表批次信息 查询营销活动信息表的批量处理情况即可
        String statPrimaryKey = "Custom" + globalInstId + "_" + mcNo;
        TMStatBak tmStatBak = selectTMStatBakByStatPrimaryKey(globalInstId, mcType, statPrimaryKey);
        //批次表为空，从来没执行过批量任务
        if (null == tmStatBak) {
            //从来没执行过批量任务，则从活动开始的第一天开始取数据
            batchDate = mcStartDate;
        } else {
            batchDate = DateUtil.getBaseDateOffsetDay(tmStatBak.getBatchDate(), 1);
        }
        //批量处理的日期小于昨天的日期，则需要取之前的数据
        while (DateUtil.compareDate(batchDate, lastDate) <= 0) {
            //获取的数据累加到活动统计中
            TMStat2CDay tmStat2CDayNew = selectToClientMcDayStatistics(globalInstId, mcNo, CommonConstant.ZERO_COMMON_CONSTANT, batchDate);
            if (null == tmStat2CDayNew) {
                rglog.error("查询用户<{}>活动<{}>对客活动单日统计表 数据查询失败!", mcNo);
                tmStat2CDayNew = new TMStat2CDay();
                tmStat2CDayNew.setTotalQtyAcc(CommonConstant.ZERO_COMMON_CONSTANT);
                tmStat2CDayNew.setTotalAmtAcc(CommonConstant.ZERO_COMMON_CONSTANT);
            }
            copytmStat2CData(tmStat2C, tmStat2CDayNew);
            //将批次日期加一天继续判断
            batchDate = DateUtil.getBaseDateOffsetDay(batchDate, 1);
        }


        //总消耗额度为周期统计表的值（已包含未跑批昨天的）+ 单日统计值
        String alredyUse = new BigDecimal(tmStat2C.getTotalAmtAcc()).add(new BigDecimal(tmStat2CDay.getTotalAmtAcc())).setScale(CommonConstant.DECIMAL_SCALE_TWO, RoundingMode.HALF_UP).toString();

        return alredyUse;
    }

    /**
     * 查询对客户营销活动统计表数据
     *
     * @param instId    法人机构号
     * @param mcNo      商户编号
     * @param ruleIndex 规则顺序号
     * @return cc.rengu.igas.momp.common.entity.TMStat2C 对客户营销活动统计表
     * @throws Exception 异常信息
     * @author liujinan
     * @since 2020/9/16 15:52
     */
    private TMStat2C selectToClientMcLevelStatistics(String instId, String mcNo, String ruleIndex) throws Exception {

        TMStat2C tmStat2C = new TMStat2C();
        tmStat2C.setInstId(instId);
        tmStat2C.setMcNo(mcNo);
        tmStat2C.setRuleIndex(ruleIndex);

        TMStat2CMapper tmStat2CMapper = new TMStat2CMapperImpl();
        return tmStat2CMapper.selectToClientMcLevelStatistics(tmStat2C);
    }

    /**
     * 查询对客户营销活动单日统计表数据
     *
     * @param instId    法人机构号
     * @param mcNo      营销活动编号
     * @param ruleIndex 规则顺序号
     * @param txnDate   交易日期
     * @return cc.rengu.igas.momp.common.entity.TMStat2CDay 对客户营销活动单日统计表
     * @throws Exception 异常信息
     * @author liujinan
     * @since 2020/9/16 15:52
     */
    private TMStat2CDay selectToClientMcDayStatistics(String instId, String mcNo, String ruleIndex, String txnDate) throws Exception {

        TMStat2CDay tmStat2CDay = new TMStat2CDay();
        tmStat2CDay.setInstId(instId);
        tmStat2CDay.setMcNo(mcNo);
        tmStat2CDay.setRuleIndex(ruleIndex);
        tmStat2CDay.setTxnDate(txnDate);

        TMStat2CDayMapper tmStat2CDayMapper = new TMStat2CDayMapperImpl();
        return tmStat2CDayMapper.selectToClientMcDayStatistics(tmStat2CDay);
    }

    /**
     * 查询手续费优惠活动已经使用的优惠额度值
     *
     * @throws Exception
     * @author liujinan
     * @date 2020/9/16
     */
    private String calMchntFeeDiscountAlredyUsedFee(String mcNo, String mcStartDate, String mcType, String mcEndDate, String mcStatus) throws Exception {
        if (McStatusEnum.DRAFT.getMcStatusCode().equals(mcStatus) || McStatusEnum.NOT_PUBLISHED.getMcStatusCode().equals(mcStatus)) {
            rglog.info("活动是草稿或未发布状态，已使用预算直接返回0.00");
            String alredyUse = CommonConstant.ZERO_AMOUNT;
            return alredyUse;
        }
        int batchStatus = CommonConstant.FLAG_NOT_SET;
        String lastDate = DateUtil.getBaseDateOffsetDay(globalTransDate, CommonConstant.MINUS_ONE);
        if (DateUtil.compareDate(lastDate, mcEndDate) > 0) {
            lastDate = mcEndDate;
        }
        String lastSecondDate = DateUtil.getBaseDateOffsetDay(lastDate, CommonConstant.MINUS_ONE);
        //查询统计信息备份表批次信息 查询营销活动信息表的批量处理情况即可
        String batchDate;
        String statPrimaryKey = "Fee" + globalInstId + "_" + mcNo;
        TMStatBak tmStatBak = selectTMStatBakByStatPrimaryKey(globalInstId, McTypeEnum.MCHNT_FEE_DISCOUNT.getMcTypeCode(), statPrimaryKey);
        //批次表为空，从来没执行过批量任务
        if (null == tmStatBak) {
            //从来没执行过批量任务，则从活动开始的第一天开始取数据
            batchDate = mcStartDate;
        } else {
            batchDate = DateUtil.getBaseDateOffsetDay(tmStatBak.getBatchDate(), 1);
        }
        /* 查询商户手续费优惠营销活动统计表数据 */
        TMStatMfd tmStatMfd = selectMchntFeeDiscountStatisticsByPK(globalInstId, mcNo, CommonConstant.ZERO_COMMON_CONSTANT);
        if (null == tmStatMfd) {
            rglog.info("机构<{}> 营销活动<{}> 规则<{}> 对客户营销活动统计表无数据!", globalInstId, mcNo, CommonConstant.ZERO_COMMON_CONSTANT);
            tmStatMfd = new TMStatMfd();
            tmStatMfd.setTotalQtyAcc(CommonConstant.ZERO_COMMON_CONSTANT);
            tmStatMfd.setTotalAmtAcc(CommonConstant.ZERO_COMMON_CONSTANT);
            tmStatMfd.setTxnQtyAcc(CommonConstant.ZERO_COMMON_CONSTANT);
            tmStatMfd.setTxnAmtAcc(CommonConstant.ZERO_COMMON_CONSTANT);
        }
        /* 查询商户手续费优惠营销活动单日统计表数据 */
        TMStatMfdDay tmStatMfdDay = selectMchntFeeDiscountDayStatisticsByPK(globalInstId, mcNo, CommonConstant.ZERO_COMMON_CONSTANT, globalTransDate);
        if (null == tmStatMfdDay) {
            rglog.error("机构<{}>的减免类营销活动<{}>的规则<{}>对客户营销活动单日统计表数据查询失败!", globalInstId, mcNo, CommonConstant.ZERO_COMMON_CONSTANT);
            //取到0条数据,说明该营销活动还未产生统计值,按所有统计值都是0进行处理
            tmStatMfdDay = new TMStatMfdDay();
            tmStatMfdDay.setTotalAmtAcc(CommonConstant.ZERO_COMMON_CONSTANT);
        }
        //批量处理的日期小于昨天的日期，则需要取之前的数据
        while (DateUtil.compareDate(batchDate, lastDate) <= 0) {
            //循环获取单日统计表数据并累加
            /* 查询商户手续费优惠营销活动单日统计表数据 规则为0的数据*/
            TMStatMfdDay tmStatMfdDayNew = selectMchntFeeDiscountDayStatisticsByPK(globalInstId, mcNo, CommonConstant.ZERO_COMMON_CONSTANT, batchDate);
            if (null == tmStatMfdDayNew) {
                rglog.info("机构<{}>的商户手续费优惠营销活动<{}>的规则<{}> 手续费减免活动单日统计表 数据查询失败!", globalInstId, mcNo, CommonConstant.ZERO_COMMON_CONSTANT);
                tmStatMfdDayNew = new TMStatMfdDay();
                tmStatMfdDayNew.setTotalQtyAcc(CommonConstant.ZERO_COMMON_CONSTANT);
                tmStatMfdDayNew.setTotalAmtAcc(CommonConstant.ZERO_COMMON_CONSTANT);
                tmStatMfdDayNew.setTxnQtyAcc(CommonConstant.ZERO_COMMON_CONSTANT);
                tmStatMfdDayNew.setTxnAmtAcc(CommonConstant.ZERO_COMMON_CONSTANT);
            } else {
                rglog.info("机构<{}>的商户手续费优惠营销活动<{}>的规则<{}> 手续费减免活动单日统计表 数据查询成功!", globalInstId, mcNo, CommonConstant.ZERO_COMMON_CONSTANT);
            }
            copyStatMfdData(tmStatMfd, tmStatMfdDayNew);
            //将批次日期加一天继续判断
            batchDate = DateUtil.getBaseDateOffsetDay(batchDate, 1);
        }


        //总消耗额度为周期统计表的值（已包含未跑批昨天的）+ 单日统计值
        String alredyUse = new BigDecimal(tmStatMfd.getTotalAmtAcc()).add(new BigDecimal(tmStatMfdDay.getTotalAmtAcc())).setScale(CommonConstant.DECIMAL_SCALE_TWO, RoundingMode.HALF_UP).toString();

        return alredyUse;
    }

    /**
     * 使用主键取手续费减免活动统计表单条数据
     *
     * @param instId    法人机构编号
     * @param mcNo      营销活动编号
     * @param ruleIndex 规则顺序号
     * @return cc.rengu.igas.momp.common.entity.TMStatMfd 手续费减免活动统计表
     * @throws Exception 异常信息
     * @author liujinan
     * @since 2020/9/16 16:38
     */
    private TMStatMfd selectMchntFeeDiscountStatisticsByPK(String instId, String mcNo, String ruleIndex) throws Exception {

        TMStatMfdMapper tmStatMfdMapper = new TMStatMfdMapperImpl();
        return tmStatMfdMapper.selectMchntFeeDiscountStatisticsByPK(instId, mcNo, ruleIndex);
    }

    /**
     * 使用主键取手续费减免活动单日统计表单条数据
     *
     * @param instId    法人机构号
     * @param mcNo      营销活动编号
     * @param ruleIndex 规则顺序号
     * @param transDate 交易日期
     * @return cc.rengu.igas.momp.common.entity.TMStatMfdDay 手续费减免活动单日统计表
     * @throws Exception 异常信息
     * @author liujinan
     * @since 2020/9/16 16:38
     */
    private TMStatMfdDay selectMchntFeeDiscountDayStatisticsByPK(String instId, String mcNo, String ruleIndex, String transDate) throws Exception {

        TMStatMfdDayMapper tmStatMfdDayMapper = new TMStatMfdDayMapperImpl();
        return tmStatMfdDayMapper.selectMchntFeeDiscountDayStatisticsByPK(instId, mcNo, ruleIndex, transDate);
    }

    /**
     * 使用主键查询统计信息备份表最新一条数据
     *
     * @param instId
     * @param statType
     * @param statPrimaryKey
     * @return cc.rengu.igas.momp.common.entity.TMStatMfdPeriod
     * @throws Exception
     * @author liujinan
     * @date 2021/7/9
     */
    private TMStatBak selectTMStatBakByStatPrimaryKey(String instId, String statType, String statPrimaryKey) throws Exception {

        TMStatBakMapper tmStatBakMapper = new TMStatBakMapperImpl();
        return tmStatBakMapper.selectTMStatBakByStatPrimaryKey(instId, statType, statPrimaryKey);
    }

    /**
     * 对客活动统计表赋值
     *
     * @param tmStat2C    对客活动统计表
     * @param tmStat2CDay 对客活动单日统计
     * @author liujinan
     * @since 2021/7/12 11:23
     */
    private void copytmStat2CData(TMStat2C tmStat2C, TMStat2CDay tmStat2CDay) {

        /* 对客活动统计表-总预算累计消耗笔数 */
        tmStat2C.setTotalQtyAcc(new BigDecimal(tmStat2C.getTotalQtyAcc()).add(new BigDecimal(tmStat2CDay.getTotalQtyAcc())).toString());
        /* 对客活动统计表-总预算累计消耗金额 */
        tmStat2C.setTotalAmtAcc(new BigDecimal(tmStat2C.getTotalAmtAcc()).add(new BigDecimal(tmStat2CDay.getTotalAmtAcc())).toString());
    }

    /**
     * 手续费减免活动统计数据赋值
     *
     * @param tmStatMfd    手续费减免活动统计表
     * @param tmStatMfdDay 手续费减免活动单日统计表
     * @author Jinan Liu
     * @since 2020/6/5 11:23
     */
    private void copyStatMfdData(TMStatMfd tmStatMfd, TMStatMfdDay tmStatMfdDay) {

        /* 营销活动单日累计-总预算累计消耗笔数 */
        tmStatMfd.setTotalQtyAcc(new BigDecimal(tmStatMfd.getTotalQtyAcc()).add(new BigDecimal(tmStatMfdDay.getTotalQtyAcc())).toString());
        /* 营销活动单日累计-总预算累计消耗金额 */
        tmStatMfd.setTotalAmtAcc(new BigDecimal(tmStatMfd.getTotalAmtAcc()).add(new BigDecimal(tmStatMfdDay.getTotalAmtAcc())).setScale(CommonConstant.DECIMAL_SCALE_TWO, RoundingMode.HALF_UP).toString());
        /* 营销活动单日累计-总预算累计消耗笔数 */
        tmStatMfd.setTxnQtyAcc(new BigDecimal(tmStatMfd.getTxnQtyAcc()).add(new BigDecimal(tmStatMfdDay.getTxnQtyAcc())).toString());
        /* 营销活动单日累计-总预算累计消耗金额 */
        tmStatMfd.setTxnAmtAcc(new BigDecimal(tmStatMfd.getTxnAmtAcc()).add(new BigDecimal(tmStatMfdDay.getTxnAmtAcc())).setScale(CommonConstant.DECIMAL_SCALE_TWO, RoundingMode.HALF_UP).toString());
    }
}
